import enum

"""
任务状态枚举类
"""
class TaskStatus(enum.IntEnum):
    start_dialog = 0
    do_task = 1
    win_dialog = 2
    fail_dialog = 3
    stage_win = 4
    win_over = 5
    fail_over = 6
"""
任务基类
"""
class BaseTask:
    def __init__(self, start_dialog, win_dialog, fail_dialog):
        """
        参数初始化
        :param start_dialog: 开始对话
        :param win_dialog: 成功对话
        :param fail_dialog: 失败对话
        """
        self.start_dialog = start_dialog
        self.win_dialog = win_dialog
        self.fail_dialog = fail_dialog
        self.task_status = TaskStatus.start_dialog

    def do_task(self, key_down, key_list):
        """
        任务实现
        :param key_down:
        :param key_list:
        :return:
        """
        if key_down:
            if self.task_status == TaskStatus.start_dialog:
                self.start_dialog.next_text()
                if self.start_dialog.is_finish():
                    self.task_status = TaskStatus.do_task

            if self.task_status == TaskStatus.win_dialog:
                if self.win_dialog != None:
                    self.win_dialog.next_text()
                if self.win_dialog == None or self.win_dialog.is_finish():
                    self.task_status = TaskStatus.win_over

            if self.task_status == TaskStatus.fail_dialog:
                self.fail_dialog.next_text()
                if self.fail_dialog.is_finish():
                    self.task_status = TaskStatus.fail_over

        if self.task_status == TaskStatus.do_task:
            self.do_self_task(key_down, key_list)


    def get_status(self):
        """
        获取任务状态
        :return:
        """
        return self.task_status

    def draw(self, surface, view_x, view_y):
        """
        绘制与任务相关的场景
        :param surface:
        :param view_x:
        :param view_y:
        :return:
        """
        if self.task_status == TaskStatus.win_over or \
            self.task_status == TaskStatus.fail_over:
            return
        elif self.task_status == TaskStatus.start_dialog:
            self.start_dialog.draw(surface, None, None)
        elif self.task_status == TaskStatus.win_dialog and self.win_dialog != None:
            self.win_dialog.draw(surface, None, None)
        elif self.task_status == TaskStatus.fail_dialog:
            self.fail_dialog.draw(surface, None, None)
        self.draw_task(surface, view_x, view_y)

    def draw_task(self, surface, view_x, view_y):
        """
        子类重写该方法
        :param surface:
        :param view_x:
        :param view_y:
        :return:
        """
        pass

    def do_self_task(self, key_down, key_list):
        """
        派生类重写该方法实现具体任务
        :param key_down:
        :param key_list:
        :return:
        """
        pass
    def create_boom(self, x, y):
        """
        爆炸特效
        :param x:
        :param y:
        :return:
        """
        pass
    def create_mine(self, x, y):
        """
        创建地雷实例
        :param x:
        :param y:
        :return:
        """
        pass
    def do_collide_actor(self, actor):
        """
        实现人物之间的碰撞
        :param actor: 角色
        :return:
        """
        pass
    def do_collide_group(self):
        """
        实现组与组之间的碰撞
        :return:
        """
        pass
